package cn.smbms.config;

import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.ehcache.EhCacheCacheManager;
import org.springframework.cache.ehcache.EhCacheManagerFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;

@EnableCaching
@Configuration
public class CacheConfig {

    /**
     * 缓存管理器 使用Ehcache实现
     
    @Bean
    public ConcurrentMapCacheManager cacheManager() {
        ConcurrentMapCacheManager cacheManager = new ConcurrentMapCacheManager();
        //cacheManager.setStoreByValue(true); //true表示缓存一份副本，否则缓存引用
        return cacheManager;
    }
     */
    /**
     * 缓存管理器 使用Ehcache实现
     */
    @Bean
    public EhCacheCacheManager cacheManager() {
    	EhCacheCacheManager em = new EhCacheCacheManager();
    	EhCacheManagerFactoryBean emf = new EhCacheManagerFactoryBean();
       	emf.setConfigLocation(new ClassPathResource("ehcache.xml"));
       	emf.setCacheManagerName("springCacheManager");
       	em.setCacheManager(emf.getObject());
        return em;
    }
}
